package com.miaosha.ms_05.dao;

import com.miaosha.ms_05.domain.MiaoshaGoods;
import com.miaosha.ms_05.vo.GoodsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Description //TODO
 * @Author Administrator
 * @DATE 2020/9/23 20:26
 **/
@Mapper
public interface MiaoshaGoodsDao {

    /**
     * @param goodsId    秒杀商品ID
     * @return java.lang.Integer
     * @Description 修改秒杀活动库存
     **/
    @Update("UPDATE miaosha_goods g SET g.stock_count = stock_count -1 WHERE goods_id = #{goodsId} AND stock_count > 0")
    Integer updateStock(@Param("goodsId") Long goodsId);

    /**
     * @Description 全表秒杀库存恢复到10
     * @return void
     **/
    @Update("UPDATE miaosha_goods g SET g.stock_count = 10")
    void resetStock();

    @Select("SELECT goods_id,stock_count FROM miaosha_goods ")
    List<MiaoshaGoods> findGoodsIdAndStockCount();
}
